# Maintainer: David SEGUELA <david.seguela@delair-tech.com>

_realname=zbar
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.23.93
pkgrel=2
pkgdesc="Application and library for reading bar codes from various sources (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/mchehab/zbar"
msys2_references=(
  "cpe: cpe:/a:zbar_project:zbar"
)
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git"
         $([[ ${CARCH} == i686 ]] || echo \
           "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo" \
           "${MINGW_PACKAGE_PREFIX}-imagemagick"))
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://github.com/mchehab/zbar/archive/${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('212dfab527894b8bcbcc7cd1d43d63f5604a07473d31a5f02889e372614ebe28')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  declare -a _extra_config
  if [[ ${CARCH} == i686 ]]; then
    _extra_config+=("--without-imagemagick")
  fi

  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --without-qt \
    --without-gtk \
    --with-python=no \
    --with-directshow \
    "${_extra_config[@]}"

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}/
  make install DESTDIR="${pkgdir}"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
